﻿using ExcelConfig;
using System;
using System.Collections.Generic;

namespace synoexec.synoexec.synologylib.Helpers
{
    public static class TimeHelper
    {
        public static DateTime ST_DATE { get; internal set;} = new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc);
        /// <summary>
        /// Javascript 格式的时间戳
        /// </summary>
        public static long GetJsTime(DateTime time) {

            return (long)Math.Floor((time - ST_DATE).TotalMilliseconds);
        }
        /// <summary>
        /// 读取JS时间
        /// </summary>
        public static DateTime ReadJsTime(long time)
        {
            return new DateTime((time + ST_DATE.Millisecond)* 10000);
        }
        /// <summary>
        /// 读取时区偏移
        /// </summary>
        /// <returns></returns>
        public static TimeSpan ReadTimeZone()
        {
            var zone = AppConfig.ReadGobalValue<string>("时区");
            var zoneMap = AppConfig.GetExtraExcelConfig("时区");
            var zoneValue = zoneMap.ReadGlobal<double>(zone);
            return TimeSpan.FromHours(zoneValue);
        }
        /// <summary>
        /// 读取到当前时区
        /// </summary>
        /// <returns></returns>
        public static DateTime ReadToNowZone(DateTime time)
        {
            return time + ReadTimeZone();
        }
    }
}
